﻿//using System;
//using System.Collections.Generic;
//using System.Linq;
//using System.Web.Http;
//using System.Web.Http.Description;
//using System.Xml.Linq;
//using Kingdee.BOS.JSON;
//using Kingdee.BOS.Orm.DataEntity;
//using SDWXServer.KD;
//using SDWXServer.Models;

//namespace SDWXServer.Controllers
//{
//    /// <summary>
//    /// 微信支付
//    /// </summary>
//    public class PayController : ApiController
//    {
//        /// <summary>
//        /// 预支付
//        /// </summary>
//        /// <param name="userToken">用户令牌</param>
//        /// <param name="total_fee">金额</param>
//        /// <param name="body">描述</param>
//        /// <returns></returns>
//        [HttpGet]
//        [ResponseType(typeof(WebApiResult))]
//        public IHttpActionResult PayInfo(string userToken, string total_fee, string body)
//        {
//            var result = new WebApiResult();
//            result.Successful = true;

//            try
//            {
//                if (string.IsNullOrWhiteSpace(userToken))
//                {
//                    userToken = Guid.NewGuid().ToString();
//                }
//                var user = RedisManager.GetObject<WXUser>(userToken);
//                if (user == null)
//                {
//                    throw new Exception(string.Format("无效的userToken:{0}", userToken));
//                }

//                var totalFee = 0;
//                Int32.TryParse(total_fee, out totalFee);
//                if (totalFee <= 0) throw new Exception("支付金额必须大于0");

//                #region 金蝶云登录验证
//                LoginViewModel.CheckLogin();
//                if (LoginViewModel.Current.LoginSuccessful == false)
//                {
//                    throw new Exception("金蝶云登录失败，请稍后再尝试支付");
//                }
//                #endregion

//                totalFee = totalFee * 100;
//                result.Data = WXService.PayInfo(user.OpenId, totalFee, body, System.Web.HttpContext.Current.Request.UserHostAddress, user.Id);
//            }
//            catch (Exception e)
//            {
//                result.Successful = false;
//                result.Message = e.Message;

//                Logger.Error("PayInfo", e);
//            }

//            return Json<WebApiResult>(result);
//        }
//        /// <summary>
//        /// 支付成功回调
//        /// </summary>
//        /// <returns></returns>
//        [HttpPost]
//        public string PaySuccess()
//        {
//            //返回给微信接口 提示微信处理成功
//            var data = "{\"code\": \"SUCCESS\",\"message\": \"成功\"}";

//            try
//            {
//                //获取微信返回的数据
//                var resultFromWx = getPostStr();
//                Logger.Info(string.Format("PaySuccess - WX:{0}", resultFromWx));

//                var resultJson = Kingdee.BOS.JSON.JSONObject.Parse(resultFromWx, new Kingdee.BOS.JSON.JSONObject());
//                var event_type = resultJson.GetValue<string>("event_type", "");
//                if (event_type == "TRANSACTION.SUCCESS")
//                {
//                    Action action = () =>
//                    {
//                        var resource = resultJson.GetValue<Kingdee.BOS.JSON.JSONObject>("resource", new Kingdee.BOS.JSON.JSONObject());
//                        var ciphertext = resource.GetValue<string>("ciphertext", "");
//                        var associated_data = resource.GetValue<string>("associated_data", "");
//                        var nonce = resource.GetValue<string>("nonce", "");

//                        var text = AesGcm.AesGcmDecrypt(associated_data, nonce, ciphertext);
//                        Logger.Info("PaySuccess - TRANSACTION.SUCCESS:{0}", text);

//                        var textJson = Kingdee.BOS.JSON.JSONObject.Parse(text, new Kingdee.BOS.JSON.JSONObject());
//                        var payer = textJson.GetValue<Kingdee.BOS.JSON.JSONObject>("payer", new Kingdee.BOS.JSON.JSONObject());
//                        var openid = payer.GetValue<string>("openid", "");
//                        var transaction_id = textJson.GetValue<string>("transaction_id", "");
//                        var out_trade_no = textJson.GetValue<string>("out_trade_no", "");
//                        var attach = textJson.GetValue<string>("attach", "");
//                        var amount = textJson.GetValue<Kingdee.BOS.JSON.JSONObject>("amount", new Kingdee.BOS.JSON.JSONObject());
//                        var total = amount.GetValue<Int32>("total", 0);
//                        var totalFee = Convert.ToDecimal(total / 100m);

//                        var userToken = attach;
//                        if (string.IsNullOrWhiteSpace(userToken)) throw new Exception("userToken为空");
//                        var user = RedisManager.GetObject<WXUser>(userToken);
//                        if (user == null) return;

//                        var balanceStr = "请点击小程序查看";
//                        var remark = "感谢充值";
//                        try
//                        {
//                            #region 生成ERP的收款单
//                            #region 金蝶云登录验证
//                            LoginViewModel.CheckLogin();
//                            if (LoginViewModel.Current.LoginSuccessful == false)
//                            {
//                                throw new Exception("金蝶云登录失败");
//                            }
//                            #endregion

//                            Logger.Info(string.Format("开始生成收款单-{0}", out_trade_no));
//                            var formId = "AR_RECEIVEBILL";
//                            var dataBill = new Kingdee.BOS.JSON.JSONObject();
//                            dataBill["FPAYORGID"] = 1;
//                            dataBill["FBillNo"] = out_trade_no;
//                            dataBill["FCONTACTUNIT"] = user.CustomerIDs.FirstOrDefault();
//                            dataBill["FRECTOTALAMOUNTFOR"] = totalFee;
//                            dataBill["FACCOUNTID"] = Senparc.Weixin.Config.SenparcWeixinSetting.TenPayV3_MchId;
//                            dataBill["FCOMMENT"] = transaction_id;
//                            dataBill["FREMARK"] = openid;

//                            var client = new SD.MSXZ.K3.ServiceFacade.KDServiceClient.MSXZClientProxy();
//                            var saveResult = client.MSXZSaveBill(formId, dataBill);
//                            Logger.Info(saveResult.Message);

//                            if (saveResult.Successful)
//                            {
//                                remark = saveResult.Message;

//                                var amountObj = client.BySettleGetReceivableAmount("1", user.CustomerIDs.FirstOrDefault(), 1L);
//                                if (amountObj.Successful)
//                                {
//                                    var balance = amountObj.Result.GetValue<decimal>("ReceivableAmount", 0m);
//                                    balanceStr = balance.ToString("C");
//                                }
//                            }
//                            else
//                            {
//                                remark = saveResult.Message;
//                            }
//                            #endregion
//                        }
//                        catch (Exception exp)
//                        {
//                            Logger.Error("PaySuccess-生成ERP的收款单", exp);
//                        }

//                        WXService.SendWRZSMPMessage_PaySuccess(user.MPOpenId, user.Name, totalFee.ToString("C"), DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), balanceStr, remark);

//                        var administrators = LoginViewModel.Current.AdministratorMobile;
//                        if (string.IsNullOrWhiteSpace(administrators) == false)
//                        {
//                            var phones = administrators.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
//                            foreach (var phone in phones)
//                            {
//                                if (phone == user.PhoneNumber) continue;
//                                var userToken2 = RedisManager.GetValue<string>(phone);
//                                var user2 = RedisManager.GetObject<WXUser>(userToken2);
//                                if (user2 == null) continue;

//                                WXService.SendWRZSMPMessage_PaySuccess(user2.MPOpenId, user.Name, totalFee.ToString("C"), DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), balanceStr, remark);
//                            }
//                        }
//                    };
//                    Kingdee.BOS.KDThread.MainWorker.QuequeTask(action, (asynResult) => { });
//                }
//            }
//            catch (Exception e)
//            {
//                Logger.Error("PaySuccess", e);
//            }

//            return data;
//        }
//        private string getPostStr()
//        {
//            Int32 intLen = Convert.ToInt32(System.Web.HttpContext.Current.Request.InputStream.Length);
//            byte[] b = new byte[intLen];
//            System.Web.HttpContext.Current.Request.InputStream.Read(b, 0, intLen);
//            return System.Text.Encoding.UTF8.GetString(b);
//        }
//        /// <summary>
//        /// 获取余额
//        /// </summary>
//        /// <param name="userToken">用户令牌</param>
//        /// <returns></returns>
//        [HttpGet]
//        [ResponseType(typeof(WebApiResult))]
//        public IHttpActionResult BySettleGetReceivableAmount(string userToken)
//        {
//            var result = new WebApiResult();
//            result.Successful = true;
//            result.Data["ReceivableAmount"] = 0m;

//            try
//            {
//                if (string.IsNullOrWhiteSpace(userToken))
//                {
//                    userToken = Guid.NewGuid().ToString();
//                }
//                var user = RedisManager.GetObject<WXUser>(userToken);
//                if (user == null)
//                {
//                    throw new Exception(string.Format("无效的userToken:{0}", userToken));
//                }
//                #region 金蝶云登录验证
//                LoginViewModel.CheckLogin();
//                if (LoginViewModel.Current.LoginSuccessful == false)
//                {
//                    throw new Exception("金蝶云登录失败");
//                }
//                #endregion
//                if (user.CustomerIDs.Count == 0) throw new Exception("请首先注册为商户");

//                var client = new SD.MSXZ.K3.ServiceFacade.KDServiceClient.MSXZClientProxy();
//                var amountObj = client.BySettleGetReceivableAmount("1", user.CustomerIDs.FirstOrDefault(), 1L);
//                result.Successful = amountObj.Successful;
//                result.Message = amountObj.Message;
//                if (amountObj.Successful && amountObj.Result != null)
//                {
//                    result.Data = Newtonsoft.Json.Linq.JObject.Parse(amountObj.Result.ToString());
//                }
//            }
//            catch (Exception e)
//            {
//                result.Successful = false;
//                result.Message = e.Message;

//                Logger.Error("BySettleGetReceivableAmount", e);
//            }

//            return Json<WebApiResult>(result);
//        }
//        /// <summary>
//        /// 获取指定区间的收入支出
//        /// </summary>
//        /// <param name="userToken">用户令牌</param>
//        /// <param name="beginDateStr">开始日期2021-01-01</param>
//        /// <param name="endDateStr">结束日期2021-01-15</param>
//        /// <returns></returns>
//        [HttpGet]
//        [ResponseType(typeof(WebApiResult))]
//        public IHttpActionResult GetIncomeSpending(string userToken, string beginDateStr, string endDateStr)
//        {
//            var result = new WebApiResult();
//            result.Successful = true;
//            result.Data[""] = 0m;
//            result.Data[""] = 0m;
//            result.Data[""] = 0m;
//            result.Data[""] = 0m;

//            try
//            {
//                if (string.IsNullOrWhiteSpace(userToken))
//                {
//                    userToken = Guid.NewGuid().ToString();
//                }
//                var user = RedisManager.GetObject<WXUser>(userToken);
//                if (user == null)
//                {
//                    throw new Exception(string.Format("无效的userToken:{0}", userToken));
//                }
//                #region 金蝶云登录验证
//                LoginViewModel.CheckLogin();
//                if (LoginViewModel.Current.LoginSuccessful == false)
//                {
//                    throw new Exception("金蝶云登录失败");
//                }
//                #endregion
//                if (user.CustomerIDs.Count == 0) throw new Exception("请首先注册为商户");
//                var custId = user.CustomerIDs.FirstOrDefault();

//                DateTime beginDate;
//                DateTime.TryParse(beginDateStr, out beginDate);

//                DateTime endDate;
//                DateTime.TryParse(endDateStr, out endDate);

//                var objs = GetIncomeSpendingDetailsByK3(custId, beginDate, endDate);
//                if (objs != null)
//                {
//                    result.Data[""] = objs.Where(p => Convert.ToInt32(p["FType"]) == 0).Sum(p => Convert.ToDecimal(p["FAMOUNT"]));
//                    result.Data[""] = (-1) * objs.Where(p => Convert.ToInt32(p["FType"]) == 1).Sum(p => Convert.ToDecimal(p["FAMOUNT"]));
//                    result.Data[""] = (-1) * objs.Where(p => Convert.ToInt32(p["FType"]) == 2).Sum(p => Convert.ToDecimal(p["FAMOUNT"]));
//                    result.Data[""] = (-1) * objs.Where(p => Convert.ToInt32(p["FType"]) == 3).Sum(p => Convert.ToDecimal(p["FAMOUNT"]));
//                }
//            }
//            catch (Exception e)
//            {
//                result.Successful = false;
//                result.Message = e.Message;

//                Logger.Error("GetIncomeSpending", e);
//            }

//            return Json<WebApiResult>(result);
//        }
//        /// <summary>
//        /// 获取指定区间的收入支出明细
//        /// </summary>
//        /// <param name="userToken">用户令牌</param>
//        /// <param name="beginDateStr">开始日期2021-01-01</param>
//        /// <param name="endDateStr">结束日期2021-01-15</param>
//        /// <returns></returns>
//        [HttpGet]
//        [ResponseType(typeof(WebApiResult))]
//        public IHttpActionResult GetIncomeSpendingDetails(string userToken, string beginDateStr, string endDateStr)
//        {
//            var result = new WebApiResult();
//            result.Successful = true;
//            var details = new Newtonsoft.Json.Linq.JArray();
//            result.Data[""] = details;
//            result.Data[""] = 0m;
//            result.Data[""] = 0m;
//            result.Data[""] = 0m;
//            result.Data[""] = 0m;

//            try
//            {
//                if (string.IsNullOrWhiteSpace(userToken))
//                {
//                    userToken = Guid.NewGuid().ToString();
//                }
//                var user = RedisManager.GetObject<WXUser>(userToken);
//                if (user == null)
//                {
//                    throw new Exception(string.Format("无效的userToken:{0}", userToken));
//                }
//                #region 金蝶云登录验证
//                LoginViewModel.CheckLogin();
//                if (LoginViewModel.Current.LoginSuccessful == false)
//                {
//                    throw new Exception("金蝶云登录失败");
//                }
//                #endregion
//                if (user.CustomerIDs.Count == 0) throw new Exception("请首先注册为商户");
//                var custId = user.CustomerIDs.FirstOrDefault();

//                DateTime beginDate;
//                DateTime.TryParse(beginDateStr, out beginDate);

//                DateTime endDate;
//                DateTime.TryParse(endDateStr, out endDate);

//                var objs = GetIncomeSpendingDetailsByK3(custId, beginDate, endDate);
//                if (objs != null)
//                {
//                    result.Data[""] = objs.Where(p => Convert.ToInt32(p["FType"]) == 0).Sum(p => Convert.ToDecimal(p["FAMOUNT"]));
//                    result.Data[""] = (-1) * objs.Where(p => Convert.ToInt32(p["FType"]) == 1).Sum(p => Convert.ToDecimal(p["FAMOUNT"]));
//                    result.Data[""] = (-1) * objs.Where(p => Convert.ToInt32(p["FType"]) == 2).Sum(p => Convert.ToDecimal(p["FAMOUNT"]));
//                    result.Data[""] = (-1) * objs.Where(p => Convert.ToInt32(p["FType"]) == 3).Sum(p => Convert.ToDecimal(p["FAMOUNT"]));

//                    var balance = 0m;
//                    foreach (var obj in objs)
//                    {
//                        var type = Convert.ToInt32(obj["FType"]);
//                        var amount = Convert.ToDecimal(obj["FAMOUNT"]);
//                        balance += amount;
//                        var item = new Newtonsoft.Json.Linq.JObject();
//                        details.Add(item);

//                        //item["FTypeName"] = type == 0 ? "店铺充值" : "店铺扣点";
//                        var typeName = "";
//                        switch (type)
//                        {
//                            case 1:
//                                #region 店铺扣点
//                                typeName = "店铺扣点";
//                                #endregion
//                                break;
//                            case 2:
//                                #region 商户自配返点
//                                typeName = "商户自配返点";

//                                #endregion
//                                break;
//                            case 3:
//                                #region 餐损返点
//                                typeName = "餐损返点";
//                                #endregion
//                                break;
//                            default:
//                                #region 店铺充值
//                                typeName = "店铺充值";
//                                #endregion
//                                break;
//                        }
//                        item["FTypeName"] = typeName;
//                        item["FPriceQty"] = 0m;
//                        foreach (var prop in obj.DynamicObjectType.Properties)
//                        {
//                            item[prop.Name] = new Newtonsoft.Json.Linq.JValue(obj[prop.Name]);
//                        }
//                        if (type != 0)
//                        {
//                            item["FCREATEDATE"] = item["FDATE"];
//                        }
//                        item["FBalance"] = balance;
//                    }
//                }
//            }
//            catch (Exception e)
//            {
//                result.Successful = false;
//                result.Message = e.Message;

//                Logger.Error("GetIncomeSpendingDetails", e);
//            }

//            return Json<WebApiResult>(result);
//        }
//        /// <summary>
//        /// 生成充值记录单
//        /// </summary>
//        /// <param name="csdatas">充值记录单参数</param>
//        /// <returns></returns>
//        [HttpPost]
//        [ResponseType(typeof(WebApiResult))]
//        public IHttpActionResult MakeCSFDApplyBill([FromBody] MakeCSFDApplyParam csdatas)
//        {
//            var result = new WebApiResult();
//            result.Successful = true;
//            try
//            {
//                if (string.IsNullOrWhiteSpace(csdatas.UserToken))
//                {
//                    csdatas.UserToken = Guid.NewGuid().ToString();
//                }
//                var user = RedisManager.GetObject<WXUser>(csdatas.UserToken);
//                if (user == null)
//                {
//                    throw new Exception(string.Format("无效的userToken:{0}", csdatas.UserToken));
//                }
//                if (string.IsNullOrWhiteSpace(csdatas.orderNO))
//                {
//                    throw new Exception("失败，订单号不能为空！");
//                }
//                var applyamount = 0M;
//                Decimal.TryParse(csdatas.apply_amount, out applyamount);
//                if (applyamount <= 0M) throw new Exception("报损金额必须大于0！");
//                var pictures = new JSONArray();
//                if (csdatas.Pictures != null && csdatas.Pictures.Length > 0)
//                {
//                    foreach (var p in csdatas.Pictures)
//                    {
//                        //将base64头部信息替换
//                        var base64 = p.Replace("data:image/png;base64,", "").Replace("data:image/jgp;base64,", "").Replace("data:image/jpg;base64,", "").Replace("data:image/jpeg;base64,", "");
//                        pictures.Add(base64);
//                    }
//                }
//                var billId = 0L;
//                billId = csdatas.BillId;
//                var documentStatus = "";
//                documentStatus = csdatas.DocumentStatus;
//                #region 金蝶云登录验证
//                LoginViewModel.CheckLogin();
//                if (LoginViewModel.Current.LoginSuccessful == false)
//                {
//                    throw new Exception("金蝶云登录失败，请稍后再尝试发起申请");
//                }
//                #endregion
//                Logger.Info(string.Format("开始生成充值记录单-订单号{0}", csdatas.orderNO));
//                var formId = "SD_CSFDApplyBill";
//                var dataBill = new Kingdee.BOS.JSON.JSONObject();
//                dataBill["FORGID"] = 1;
//                dataBill["Id"] = billId;
//                dataBill["FDocumentStatus"] = documentStatus;
//                dataBill["FCUSTOMERID"] = user.CustomerIDs.FirstOrDefault();
//                dataBill["ForderNO"] = csdatas.orderNO;
//                dataBill["Fbsamount"] = applyamount;
//                dataBill["FPictures"] = pictures;

//                var client = new SD.MSXZ.K3.ServiceFacade.KDServiceClient.MSXZClientProxy();
//                var saveResult = client.MSXZSaveBill(formId, dataBill);
//                Logger.Info(saveResult.Message);
//                result.Successful = saveResult.Successful;
//                result.Message = saveResult.Message;
//            }
//            catch (Exception e)
//            {
//                result.Successful = false;
//                result.Message = e.Message;

//                Logger.Error("CSFDApply", e);
//            }
//            return Json<WebApiResult>(result);
//        }
//        /// <summary>
//        /// 获取指定区间的充值记录单
//        /// </summary>
//        /// <param name="userToken">用户令牌</param>
//        /// <param name="beginDateStr">开始日期2021-01-01</param>
//        /// <param name="endDateStr">结束日期2021-01-15</param>
//        /// <returns></returns>
//        [HttpGet]
//        [ResponseType(typeof(WebApiResult))]
//        public IHttpActionResult GetCSFDApplyList(string userToken, string beginDateStr, string endDateStr)
//        {
//            var result = new WebApiResult();
//            result.Successful = true;
//            var details = new Newtonsoft.Json.Linq.JArray();
//            result.Data["Lists"] = details;

//            try
//            {
//                if (string.IsNullOrWhiteSpace(userToken))
//                {
//                    userToken = Guid.NewGuid().ToString();
//                }
//                var user = RedisManager.GetObject<WXUser>(userToken);
//                if (user == null)
//                {
//                    throw new Exception(string.Format("无效的userToken:{0}", userToken));
//                }
//                #region 金蝶云登录验证
//                LoginViewModel.CheckLogin();
//                if (LoginViewModel.Current.LoginSuccessful == false)
//                {
//                    throw new Exception("金蝶云登录失败");
//                }
//                #endregion
//                if (user.CustomerIDs.Count == 0) throw new Exception("请首先注册为商户");
//                var custId = user.CustomerIDs.FirstOrDefault();
//                DateTime beginDate;
//                DateTime.TryParse(beginDateStr, out beginDate);

//                DateTime endDate;
//                DateTime.TryParse(endDateStr, out endDate);

//                var objs = GetCSFDApplyDatas(custId, beginDate, endDate);
//                if (objs != null)
//                {
//                    foreach (var obj in objs)
//                    {
//                        var fid = Convert.ToInt64(obj["FID"]);
//                        var billNO = Convert.ToString(obj["FBILLNO"]);
//                        var billTypeId = Convert.ToString(obj["FBILLTYPEID"]);
//                        var status = Convert.ToString(obj["FDOCUMENTSTATUS"]);
//                        var createDate = Convert.ToDateTime(obj["FCREATEDATE"]);
//                        var date = Convert.ToDateTime(obj["FDATE"]).Date;
//                        var orderNO = Convert.ToString(obj["FORDERNO"]);
//                        var bsAmount = Convert.ToDecimal(obj["FBSAMOUNT"]);
//                        var dsAmount = Convert.ToDecimal(obj["FDSAMOUNT"]);

//                        var item = new Newtonsoft.Json.Linq.JObject();
//                        details.Add(item);

//                        var billTypeName = "充值记录单";
//                        var statusName = "";
//                        switch (status)
//                        {
//                            case "Z":
//                                #region 暂存
//                                statusName = "暂存";
//                                #endregion
//                                break;
//                            case "A":
//                                #region 创建
//                                statusName = "创建";
//                                #endregion
//                                break;
//                            case "B":
//                                #region 审核中
//                                statusName = "审核中";
//                                #endregion
//                                break;
//                            case "C":
//                                #region 已审核
//                                statusName = "已审核";
//                                #endregion
//                                break;
//                            case "D":
//                                #region 重新审核
//                                statusName = "重新审核";
//                                #endregion
//                                break;
//                            default:
//                                #region 状态错误
//                                statusName = "状态错误";
//                                #endregion
//                                break;
//                        }

//                        item["FId"] = fid;
//                        item["FBillTypeId"] = billTypeId;
//                        item["FBillTypeName"] = billTypeName;
//                        item["FStatus"] = status;
//                        item["FStatusName"] = statusName;
//                        item["FCreateDate"] = createDate;
//                        item["FBillNO"] = billNO;
//                        item["FDate"] = date;
//                        item["FOrderNO"] = orderNO;
//                        item["FBsAmount"] = bsAmount;
//                        item["FDsAmount"] = dsAmount;
//                    }
//                }
//            }
//            catch (Exception e)
//            {
//                result.Successful = false;
//                result.Message = e.Message;

//                Logger.Error("GetCSFDApplyList", e);
//            }

//            return Json<WebApiResult>(result);
//        }
//        private DynamicObjectCollection GetIncomeSpendingDetailsByK3(Int64 custId, DateTime beginDate, DateTime endDate)
//        {
//            DynamicObjectCollection objs = null;
//            try
//            {
//                var sqlGetCustomer = @"/*dialect*/
//SELECT S.*
//FROM (
//SELECT T0.FBILLNO,T0.FDATE,T0.FCREATEDATE,T1.FALLAMOUNTFOR*(-1) AS FAMOUNT,1 AS FType,T1.FPriceQty
//  FROM t_AR_receivable T0
//	INNER JOIN t_AR_receivableEntry T1 ON T1.FID = T0.FID
//	INNER JOIN t_AR_receivableEntry_O T2 ON T2.FENTRYID = T1.FENTRYID
//	INNER JOIN T_BD_EXPENSE F ON F.FEXPID = T2.FCOSTID
//WHERE T0.FBILLTYPEID = '00505694799c955111e325bc9e6eb056' AND T0.FDOCUMENTSTATUS = 'C' AND T0.FSETACCOUNTTYPE <> '2' AND T0.FREDBLUE = '0'
//AND T0.FCUSTOMERID = @FCUSTOMERID
//AND F.FNUMBER = 'DPKD' AND T0.FDATE >= @FBEGIN AND T0.FDATE <= @FEND
//UNION ALL
//SELECT T0.FBILLNO,T0.FDATE,T0.FCREATEDATE,T1.FALLAMOUNTFOR*(-1) AS FAMOUNT,2 AS FType,T1.FPriceQty
//  FROM t_AR_receivable T0
//	INNER JOIN t_AR_receivableEntry T1 ON T1.FID = T0.FID
//	INNER JOIN t_AR_receivableEntry_O T2 ON T2.FENTRYID = T1.FENTRYID
//	INNER JOIN T_BD_EXPENSE F ON F.FEXPID = T2.FCOSTID
//WHERE T0.FBILLTYPEID = '00505694799c955111e325bc9e6eb056' AND T0.FDOCUMENTSTATUS = 'C' AND T0.FSETACCOUNTTYPE <> '2' AND T0.FREDBLUE = '0'
//AND T0.FCUSTOMERID = @FCUSTOMERID
//AND F.FNUMBER = 'SHZPFD' AND T0.FDATE >= @FBEGIN AND T0.FDATE <= @FEND
//UNION ALL
//SELECT T0.FBILLNO,T0.FDATE,T0.FCREATEDATE,T1.FALLAMOUNTFOR*(-1) AS FAMOUNT,3 AS FType,T1.FPriceQty
//  FROM t_AR_receivable T0
//	INNER JOIN t_AR_receivableEntry T1 ON T1.FID = T0.FID
//	INNER JOIN t_AR_receivableEntry_O T2 ON T2.FENTRYID = T1.FENTRYID
//	INNER JOIN T_BD_EXPENSE F ON F.FEXPID = T2.FCOSTID
//WHERE T0.FBILLTYPEID = '00505694799c955111e325bc9e6eb056' AND T0.FDOCUMENTSTATUS = 'C' AND T0.FSETACCOUNTTYPE <> '2' AND T0.FREDBLUE = '0'AND T0.FCUSTOMERID = @FCUSTOMERID
//AND F.FNUMBER = 'CSFD' AND T0.FDATE >= @FBEGIN AND T0.FDATE <= @FEND
//UNION ALL
//SELECT T0.FBILLNO,T0.FDATE,T0.FCREATEDATE,T1.FREALRECAMOUNTFOR AS FAMOUNT,0 AS FType,0.0 AS FPriceQty
//  FROM T_AR_RECEIVEBILL T0
//	INNER JOIN T_AR_RECEIVEBILLENTRY T1 ON T1.FID = T0.FID
//WHERE T0.FBILLTYPEID = '36cf265bd8c3452194ed9c83ec5e73d2' AND T0.FDOCUMENTSTATUS = 'C'
//AND T0.FPAYUNIT = @FCUSTOMERID AND T1.FSETTLETYPEID = 30604 AND T1.FPURPOSEID = 20011
//AND T0.FDATE >= @FBEGIN AND T0.FDATE <= @FEND
//) S
//ORDER BY S.FCREATEDATE,S.FType,S.FBILLNO
//";
//                var lst = new List<Kingdee.BOS.SqlParam>();
//                var sqlSvr = new SD.MSXZ.K3.ServiceFacade.KDServiceClient.MSXZClientProxy();
//                lst.Add(new Kingdee.BOS.SqlParam("@FCUSTOMERID", Kingdee.BOS.KDDbType.Int64, custId));
//                lst.Add(new Kingdee.BOS.SqlParam("@FBEGIN", Kingdee.BOS.KDDbType.DateTime, beginDate));
//                lst.Add(new Kingdee.BOS.SqlParam("@FEND", Kingdee.BOS.KDDbType.DateTime, endDate));
//                objs = sqlSvr.ExecuteDynamicObject(sqlGetCustomer, System.Data.CommandType.Text, lst);
//            }
//            catch (Exception e)
//            {
//                Logger.Error("GetIncomeSpendingDetails", e);
//            }

//            return objs;
//        }
//        private DynamicObjectCollection GetCSFDApplyDatas(Int64 custId, DateTime beginDate, DateTime endDate)
//        {
//            DynamicObjectCollection objs = null;
//            try
//            {
//                var sqlGetCustomer = @"/*dialect*/
//SELECT FID,FBILLNO,FBILLTYPEID,FDOCUMENTSTATUS,
//FCREATEDATE,FDATE,FORDERNO,FBSAMOUNT,FDSAMOUNT 
//FROM SD_T_CSFDApplyBill
//WHERE FCUSTOMERID= @FCUSTOMERID AND FDATE >= @FBEGIN AND FDATE <= @FEND
//";
//                var lst = new List<Kingdee.BOS.SqlParam>();
//                var sqlSvr = new SD.MSXZ.K3.ServiceFacade.KDServiceClient.MSXZClientProxy();
//                lst.Add(new Kingdee.BOS.SqlParam("@FCUSTOMERID", Kingdee.BOS.KDDbType.Int64, custId));
//                lst.Add(new Kingdee.BOS.SqlParam("@FBEGIN", Kingdee.BOS.KDDbType.DateTime, beginDate));
//                lst.Add(new Kingdee.BOS.SqlParam("@FEND", Kingdee.BOS.KDDbType.DateTime, endDate));
//                objs = sqlSvr.ExecuteDynamicObject(sqlGetCustomer, System.Data.CommandType.Text, lst);
//            }
//            catch (Exception e)
//            {
//                Logger.Error("GetIncomeSpendingDetails", e);
//            }

//            return objs;
//        }
//        /// <summary>
//        /// 生成充值记录单参数
//        /// </summary>
//        public class MakeCSFDApplyParam
//        {
//            /// <summary>
//            /// 用户令牌
//            /// </summary>
//            public string UserToken { get; set; }

//            ///// <summary>
//            ///// 业务对象标识
//            ///// </summary>
//            //public string FormId { get; set; }

//            /// <summary>
//            /// 单据内码
//            /// </summary>
//            public Int64 BillId { get; set; }

//            /// <summary>
//            /// 单据状态
//            /// </summary>
//            public string DocumentStatus { get; set; }

//            /// <summary>
//            /// 订单号
//            /// </summary>
//            public string orderNO { get; set; }

//            /// <summary>
//            /// 报损申请金额
//            /// </summary>
//            public string apply_amount { get; set; }

//            /// <summary>
//            /// 图片
//            /// </summary>
//            public string[] Pictures { get; set; }
//        }
//    }
//}